﻿using System;
using System.Collections.Generic;
using System.Text;

namespace eKanBan.Model
{
    [Serializable]
    class Phase : BasePhase
    {
        private int maxOfFeature;
        public Phase(string name, string definitionOfDone, int maxOfFeature)
            : base(name)
        {
            if (maxOfFeature < 0)
            {
                throw new Exception("maxOfFeature cannot be negative.");
            }
            this.DefinitionOfDone = definitionOfDone;
            this.maxOfFeature = maxOfFeature;
        }

        // Definition of when a feature has done a phase
        public string DefinitionOfDone { get; set; }

        // Maximum number of feature in a phase
        public int MaxFeature {
            get { return maxOfFeature; }
            set { 
                if (value < base.FeatureCount)
                {
                    throw new Exception(String.Format("Cannot set MaxFeature to {0}, number of current features in this phase is larger", value));
                }
                if (value < 0)
                {
                    throw new Exception("maxOfFeature cannot be negative.");
                }
                maxOfFeature = value;
            }             
        }

        // Addition condition for adding a phase with max feature rule
        public override bool CanAdd(Feature feature)
        {
            if (base.CanAdd(feature))
                if (base.FeatureCount < maxOfFeature)
                    return true;
            return false;
        }

        public override string ToString()
        {
            string r = base.ToString();
            r += String.Format("Definition Of Done: {0}\n", DefinitionOfDone);
            r += String.Format("Max of Feature: {0}\n", maxOfFeature);
            return r;
        }

    }
}
